package com.administrators.action;

import com.administrators.entity.Adms;

import com.administrators.services.AdmsServices;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.Map;

@Controller
@Scope("prototype")
public class AdmsAction extends ActionSupport implements ModelDriven<Adms>,SessionAware{
    private Map<String,Object> session =null;
    private Adms adms = null;
    @Autowired
    private AdmsServices admsServices = null;
    public Adms getModel() {
        this.adms = new Adms();
        return this.adms;
    }

    public void setSession(Map<String, Object> map) {
        this.session = map;
    }
    //进入登陆视图界面
    public String loginView(){
        return "loginViewSuccess";
    }
    //登陆
    public String login(){
        Adms adms1 = admsServices.login(adms);
        if(adms1==null){
            return "loginerror";
        }else{
            return "loginsuccess";
        }
    }
    public String add(){
        boolean flag = admsServices.addone(adms);
        if(flag){
            return "addSuccess";
        }else{
            return "addError";
        }
    }
    public String update(){
        boolean flag = admsServices.deleteone(adms);
        if (flag){
            return "updateSuccess";
        }else{
            return "updateSuccess";
        }
    }
}
